// -----------------------------------------------------------------------
//  <copyright file="AjaxOnlyAttribute.cs" company="OSharp开源团队">
//      Copyright (c) 2014-2017 OSharp. All rights reserved.
//  </copyright>
//  <site>http://www.osharp.org</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2017-09-01 18:11</last-date>
// -----------------------------------------------------------------------


namespace OSharp.AspNetCore.Mvc.Filters;

/// <summary>
/// 限制当前功能只允许以Ajax的方式来访问
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class AjaxOnlyAttribute : ActionFilterAttribute
{
    /// <inheritdoc />
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        if (!context.HttpContext.Request.IsAjaxRequest())
        {
            context.Result = new ContentResult()
            {
                Content = "当前功能只支持使用Ajax的方式来调用。"
            };
        }
    }
}
